package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.OperLogMapper;
import com.situ.mymall.pojo.entity.OperLog;
import com.situ.mymall.pojo.query.OperLogQuery;
import com.situ.mymall.service.IOperLogService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperLogServiceImpl implements IOperLogService {

    @Autowired
    private OperLogMapper operLogMapper;

    @Override
    public void add(OperLog operLog) {
        operLogMapper.insertSelective(operLog);
    }

    @Override
    public PageResult list(OperLogQuery operLogQuery) {
        //使用PageHelper开启分页
        PageHelper.startPage(operLogQuery.getPage(),operLogQuery.getLimit());
        //开启分页之后 LIMIT offset,pageSize 这个代码
        List<OperLog> list = operLogMapper.list(operLogQuery);
        //查找总数量PageHelper会自动帮我们完成
        //int totalCount = blogMapper.selectTotalCount(blogQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();
        return PageResult.ok(totalCount,list);
    }

    @Override
    public OperLog selectById(Integer id) {
        return operLogMapper.selectById(id);
    }
}
